package com.example.demo11.controller
import java.util

import com.example.demo11.domian.User2
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod, RestController}

import scala.collection.JavaConverters


@Controller
class scalaController {
  @RequestMapping(value = Array("scalaUser/{userId}"), method = Array(RequestMethod.GET))
  def getUser(@PathVariable("userId") id:String, model:Model):String = {
    val user = new User2("coxx", "123456", "coxx@vip.qq.com", "jie")
    model.addAttribute("user", user)
    model.addAttribute("id", id)
    val temp:Map[String, Object] = Map("a"->"A", "b"-> "C", "d" -> "D", "e" -> null)
    val mapTest:util.Map[String, Object] = JavaConverters.mapAsJavaMap(temp); //转换为java map
    print("a:" + mapTest.get("a"))
    print(" b:" + mapTest.get("b"))
    print(" c:" + mapTest.get("c"))
    print(" d:" + mapTest.get("d"))
    println(" e:" + mapTest.get("e"))
    model addAllAttributes mapTest
    "user/index"
  }
}

